import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { ossUri, VOD_CATEGORY, VOD_CATEGORY_SAVE } from 'src/app/service/action_type';
import { CustomService } from 'src/app/service/custom.service';
import { RequestService } from 'src/app/service/request.service';

@Component({
  selector: 'app-vod-category',
  templateUrl: './vod-category.component.html',
  styleUrls: ['./vod-category.component.less']
})
export class VodCategoryComponent implements OnInit {

  datalist: any[] = [];
  ossUrl: string = ossUri;
  maxVodCategoryCount: number = 0;

  createNew() {
    this.requestService.post(VOD_CATEGORY_SAVE, { 'name': '新建视频库' }).subscribe(result => {
      this.datalist.push(result['data']);
    })
  }

  getList() {
    this.requestService.get(VOD_CATEGORY).subscribe(result => {
      this.datalist = result['data'];
    })
  }

  changName(index: number) {
    this.requestService.post(VOD_CATEGORY_SAVE, this.datalist[index]).subscribe(result => {
    })
  }

  goVod(index: number, e: any) {
    if (e.target.tagName !== 'INPUT')
      this.router.navigateByUrl('/main/vod/lib/' + this.datalist[index]['id'].toString());
  }

  constructor(private requestService: RequestService, private router: Router, private customService: CustomService) { }

  ngOnInit(): void {
    this.getList();
    this.customService.profile().subscribe(result => {
      this.maxVodCategoryCount = result['data']['maxVodCategoryCount'];
    });
  }

}
